package com.yzt.redpack;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yzt.redpack.adapter.RedPkgDetailAdapter;
import com.yzt.redpack.R;
import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.dynamic.RedPkgDetailBean;
import com.yzt.zhuju.widget.widget.ImageLoadManger;

/**
 * 作者：bobwang
 * 创建时间：2023-11-20 22:52:29
 * 描述：红包详情
 */
public class RedPkgDetailActivity extends BaseActivity {

    private String redPacketId;

    private RedPkgDetailAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_red_pkg_detail;
    }

    @Override
    public void installViews() {
        redPacketId = getIntent().getStringExtra("extra_id");
        mTitleBar.setTitle("");
        RecyclerView recycle = findViewById(R.id.recycler_view);
        recycle.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new RedPkgDetailAdapter();
        recycle.setAdapter(adapter);
        getRedPacketDetail();
    }

    /**
     * 红包详情
     */
    private void getRedPacketDetail() {
        BizLayer.getInstance().getDynamicModule().getRedPacketGetInfo(redPacketId, new AresSubscriber<RedPkgDetailBean>() {
            @Override
            protected void onSuccess(RedPkgDetailBean redPkgInfo) {
                ImageLoadManger.loadIv(mActivity, redPkgInfo.getAvatar(), findViewById(R.id.img_avatar));
                ((TextView) findViewById(R.id.tv_title)).setText(redPkgInfo.getTitle());
                ((TextView) findViewById(R.id.tv_desc)).setText(redPkgInfo.getDsc());

                // 我领取到的
                if (redPkgInfo.getCandyCoin() != null) {
                    findViewById(R.id.ll_i_get_container).setVisibility(View.VISIBLE);
                    ((TextView) findViewById(R.id.tv_candy_count1)).setText(redPkgInfo.getOpenInfo());
                    ((TextView) findViewById(R.id.tv_get_count)).setText(redPkgInfo.getCandyCoin());
                } else {
                    ((TextView) findViewById(R.id.tv_candy_count)).setText(redPkgInfo.getOpenInfo());
                }
                adapter.setList(redPkgInfo.getUserList());
            }
        });
    }
}